<template>
    利息:
    <select v-model="Lid">
        <option value="0">请选择</option>
        <option v-for="i in info" :value="i.FIid">{{ i.FIname }}%</option>
    </select>
    <button @click="Show">查询</button>
<table border="1">
    <tr>
        <td>理财名称</td>
        <td>年收益</td>
        <td>利息</td>
        <td>最低金额</td>
        <td>理财人次</td>
        <td>风险等级</td>
        <td>操作</td>
    </tr>
    <tr v-for="i in data">
        <td>{{ i.Fname }}</td>
        <td>{{ i.FARY }}</td>
        <td>{{ i.FIname }}%</td>
        <td>{{ i.Fminmoney.toFixed(2) }}CNY</td>
        <td>{{ i.Fnum }}</td>
        <td>{{ i.Flevel==1?"低风险":i.Flevel==2?"中风险":"高风险" }}</td>
        <td><a href="#" @click="Go(i.Fid)">查看明细</a></td>
    </tr>
</table>

<a href="#" @click="PageChange('F')">首页</a>
<a href="#" @click="PageChange('P')">上一页</a>
<a href="#" @click="PageChange('N')">下一页</a>
<a href="#" @click="PageChange('L')">尾页</a>
一页 <input type="text" v-model="Csize">条
<button @click="ChangSize">Go</button>


</template>
<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted}from 'vue'
import {useRouter} from 'vue-router'
const Csize=ref(2)
const router=useRouter()
const info=ref([{
    FIid:0,
    FIname:''
}])
const Lid=ref(0)
const PageInfo=ref({
    PageIndex:1,
    PageSize:2,
    PageCount:0,
    ReCount:0
})
const data=ref([{
    Fname:'',
    Fid:0,
    FARY:0,
    Fnum:0,
    FIname:'',
    Fminmoney:0,
    Flevel:0,
}])
onMounted(()=>{
    Bind()
    Show()
})
const Bind=()=>{
    axios.get("https://localhost:44396/api/Finan/Bind",
        {

        }
    ).then(res=>{
        info.value=res.data
    }).catch(err=>{
        console.log(err)
    })
}
const Show=()=>{
    axios.get("https://localhost:44396/api/Finan/PageShowFinanInfo",
        {
            params:{
                FIid:Lid.value,
                PageIndex:PageInfo.value.PageIndex,
                PageSize:PageInfo.value.PageSize
            }
        }
    ).then(res=>{
        data.value=res.data.list
        PageInfo.value.PageCount=res.data.PageCount
        PageInfo.value.ReCount=res.data.ReCount
        console.log(res.data)
    }).catch(err=>{
        console.log(err)
    })
}

const PageChange=(m:string)=>{
    if(m=="F"){
        PageInfo.value.PageIndex=1
    }
    if(m=="L"){
        PageInfo.value.PageIndex=PageInfo.value.PageCount
    }
    if(m=="P"){
        if(PageInfo.value.PageIndex==1){
            
            return
        }
        PageInfo.value.PageIndex--
    }
    if(m=="N"){
        if(PageInfo.value.PageIndex==PageInfo.value.PageCount){
            
            return
        }
        PageInfo.value.PageIndex++
    }
    Show()
}
const Go=(Fid:number)=>{
    router.push(
        {
            path:'/AddUserFinan',
            query:{
                Fid:Fid
            }
        }
    )
}

const ChangSize=()=>{
    if(Csize.value>PageInfo.value.ReCount||Csize.value<0){
        return
    }
    PageInfo.value.PageSize=Csize.value
    Show()
}

</script>